
    (function() {
            //随机小方格
            //1构造函数
            
            function Food (x,y,width,height,color) {
                this.x = x || 0
                this.y = y || 0
                this.width = width || 20
                this.height = height || 20
                this.color = color || "blue"
            }
            var elements = []
            //2实例化
            Food.prototype.init = function (map) {
                remove()
                var div = document.createElement("div")
                map.appendChild(div)
                div.style.width = this.width + "px"
                div.style.height = this.height + "px"
                div.style.backgroundColor = this.color
                div.style.position = "absolute"
                //产生随机坐标
                this.x = parseInt(Math.random()*(map.offsetHeight/this.height))*this.height
                this.y = parseInt(Math.random()*(map.offsetHeight/this.width))*this.width
                div.style.left = this.x + "px"
                div.style.top = this.y + "px"

                elements.push(div)
            }

            function remove () {
                for (var i = 0; i < elements.length; i++) {
                    var ele = elements[i]
                    ele.parentNode.removeChild(ele)
                    elements.splice(i,1)
                }
            }

            window.Food = Food
        }());
